package sicnu.cs.aps.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author CaiKe
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment envi) {

        Profiles profiles = Profiles.of("dev", "test");
        boolean isDev = envi.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                // 配置Swagger
                .apiInfo(apiInfo())
                .enable(isDev)
                .select()
                .apis(RequestHandlerSelectors.basePackage("sicnu.cs.aps.rest"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfo(
                "APS",
                "招生宣传系统API文档",
                "1.0",
                "http://aps.sicnu.edu.cn/",
                new Contact(
                        "cs",
                        "http://cs.sicnu.edu.cn/",
                        "@sicnu.edu.cn"
                ),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>()
        );
    }

}